﻿using System;
using System.Collections.Generic;
using System.Text;


using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
using OT.Module.ModelConst;
using OT.Common;
using OT.EntLib.Validate;

namespace OT.Module.Model
{
    [OptimisticLocking(false)]
    [Persistent(GDB.Emp)]
    public partial class Emp : XPLiteObject
    {
        #region ~

        /// <summary>
        /// 构造函数
        /// </summary>
        public Emp() : base ( new Session() )
        {

        }

        public Emp(Session s)
            : base(s)
        {
        }

        public Emp(Session s, XPClassInfo info)
            : base(s, info)
        {
        }

        #endregion

        #region ID

        private string _ID = "";
        /// <summary>
        /// 
        /// </summary>
        /// 
        [Key(false)]
        public string ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }
        #endregion

        #region Name
        private string _Name = "";
        [DisplayName(GSyntax.Emp.Name)]
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                SetPropertyValue("Name", ref _Name, value);
            }
        }
        #endregion

        #region Age
        private int _Age = 0;
        [DisplayName(GSyntax.Emp.Age)]
        public int Age
        {
            get { return _Age; }
            set { _Age = value; }
        }
        #endregion

        #region Money
        private decimal _Money = 0;
        [DisplayName(GSyntax.Emp.Money)]
        public decimal Money
        {
            get { return _Money; }
            set { _Money = value; }
        }
        #endregion

        #region Note
        private string _Note = "";
        [DisplayName(GSyntax.Emp.Note)]
        public string Note
        {
            get
            {
                return _Note;
            }
            set
            {
                SetPropertyValue("Note", ref _Note, value);
            }
        }
        #endregion

        #region Birthday
        private DateTime _Birthday = DateTime.MinValue;
        [DisplayName(GSyntax.Emp.Birthday)]
        public DateTime Birthday
        {
            get { return _Birthday; }
            set { _Birthday = value; }
        }
        #endregion

        #region Sex
        private Sex _Sex ;
        [DisplayName(GSyntax.Emp.Sex)]
        public Sex Sex
        {
            get
            {
                return _Sex;
            }
            set
            {
                SetPropertyValue("Sex", ref _Sex, value);
            }
        }
        #endregion

        #region IsInComp
        private int _IsInComp = 1;
        [DisplayName(GSyntax.Emp.IsInComp)]
        public int IsInComp
        {
            get { return _IsInComp; }
            set { _IsInComp = value; }
        }
        #endregion


        #region BelongCompany
        private Company _BelongCompany;

        [Association("Company-Emps")]
        [Persistent("CompID")]
        public Company BelongCompany
        {
            get
            {
                return _BelongCompany;
            }
            set
            {
                SetPropertyValue("BelongCompany", ref _BelongCompany, value);
            }
        }
        #endregion

        #region CompID
        [DisplayName(GSyntax.Emp.CompID)]
        [NonPersistent]
        public string CompID
        {
            get
            {
                string ret = "";
                if (BelongCompany != null)
                    ret = BelongCompany.CompanyID;
                return ret;
            }
            set
            {
                BelongCompany = Session.GetObjectByKey<Company>(value);
            }
        }
        #endregion

        #region IsInCompStatus
        [DisplayName(GSyntax.Emp.IsInComp)]
        public string IsInCompStatus
        {
            get 
            {
                if (IsInComp == 1)
                    return "是";
                else
                    return "否";
            }
        }
        #endregion

        #region SexText
        [DisplayName(GSyntax.Emp.Sex)]
        [NonPersistent]
        public string SexText
        {
            get
            {
                return EnumUtility.GetEnumCaption(typeof(Sex),Sex);
            }
            set
            {
                Sex = EnumUtility.GetEnumValue<Sex>(value);
            }
        }
        #endregion
    }
}
